﻿using Microsoft.EntityFrameworkCore;
using Mvc.Sample.Data.DataSeeding;
using Mvc.Sample.Models;

namespace Mvc.Sample.Data;

public class ApplicationDbContext(
    DbContextOptions<ApplicationDbContext> options
) : DbContext(options)
{
    public DbSet<TodoItem> TodoItems { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseSqlite("Data Source=database.db")
            .UseSeeding((context, _) =>
            {
                context.AddRange(new TodoItemDataSeeding().HasData());
                context.SaveChanges();
            });
    
    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);
        builder.ApplyConfigurationsFromAssembly(typeof(ApplicationDbContext).Assembly);
    }
}
